package lee.lxwei.boot.web;

import lee.lxwei.boot.dto.UserRegistReq;
import lee.lxwei.boot.service.UserLoginService;
import lee.lxwei.boot.service.UserRegistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 以用户注册退出 触发事件处理
 */
@RestController
@RequestMapping("user")
public class UserInfoController {

    @Autowired
    private UserRegistService userRegistService;
    @Autowired
    private UserLoginService userLoginService;

    @PostMapping("regist")
    public String regist(@RequestBody UserRegistReq registReq) {
        return userRegistService.regist(registReq.getName()) ? "success" : "fail";
    }

    @PostMapping("out")
    public String out(@RequestBody UserRegistReq registReq) {
        return userLoginService.loginOut(registReq.getName()) ? "success" : "fail";
    }

}
